package com.gradle.quartz.batch.listener;

import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.stereotype.Component;


/**
 * 统计数据读写所消耗的时间
 *
 * @author ldanniel
 */
@Component
public class FileToDbJobListener implements JobExecutionListener {
    @Override
    public void beforeJob(JobExecution jobExecution) {
        long startTime = System.currentTimeMillis();
        //作业上下文数据共享
        jobExecution.getExecutionContext().putLong("startTime", startTime);
        System.out.println("--------------- 【FileToDb开始时间：】--->【" + startTime + "】 <---------------");
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        long endTime = System.currentTimeMillis();
        long startTime = jobExecution.getExecutionContext().getLong("startTime");
        System.out.println("--------------- 【FileToDb结束时间：】--->【" + endTime + "】 <---------------");
        System.out.println("--------------- 【FileToDb总耗时：】--->【" + (endTime - startTime) + "】 <---------------");
    }
}
